DROP TRIGGER ON_USER_LOCATION_CHANGE;
DROP TRIGGER ON_APPOINTMENT_DELETE;

CREATE TRIGGER ON_USER_LOCATION_CHANGE
AFTER UPDATE OF L_ID ON PERSONAL_DATA
FOR EACH ROW
MODE DB2SQL
delete FROM location
WHERE L_ID NOT IN (SELECT L_ID FROM personal_data) 
and L_ID NOT IN (SELECT L_ID FROM appointment);

CREATE TRIGGER ON_APPOINTMENT_DELETE
AFTER DELETE ON APPOINTMENT
FOR EACH ROW
MODE DB2SQL
delete FROM location
WHERE L_ID NOT IN (SELECT L_ID FROM personal_data) 
and L_ID NOT IN (SELECT L_ID FROM appointment);